﻿// Copyright (c) .NET Core Community. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using DotNetCore.CAP;
using DotNetCore.CAP.RabbitMQ;
using DotNetCore.CAP.Transport;
using Microsoft.Extensions.DependencyInjection;

// ReSharper disable once CheckNamespace
namespace Seagull.Extensions.ServiceBus
{
    internal sealed class DelayCapOptionsExtension : ICapOptionsExtension
    {
        private readonly Action<DelayOptions> _configure;

        public DelayCapOptionsExtension(Action<DelayOptions> configure)
        {
            _configure = configure;
        }

        public void AddServices(IServiceCollection services)
        {
            services.Configure(_configure);
            services.AddSingleton<ITransport, RabbitMQTransport>();
            //Startup and Hosted 
            services.AddSingleton<HostedService>();
            services.AddHostedService(sp => sp.GetRequiredService<HostedService>());
        }
    }
}